var orderId = $Util.getQueryString(document.location.search, "id");
$(function(){
	$(".mc").css("display","none");
	$('#categorys').hover(function(){
		$(this).children('.mc').toggle();
	});
	$Base.isLogin(location.href, getOrderDetail);
});

function feedback(){
	location.href = "evaluate.html?id=" + orderId;
}

function getOrderDetail(){
	var url = "/json?action=GET_T_ORDER_BY_MEMBER_ACTION&ORDER_ID="+orderId;
	$.post(url, {}, function(data){
		if(data.success){
			var obj = data.root.T_ORDER.rs[0];
			var order = obj.ORDER;
			var detail = obj.DETAIL;
			var log = obj.LOG;
			var status = order.STATUS;
			
			var flow = obj.FLOW;
			var newOrder = flow.WAIT_STATUS;
			var proccess = flow.PROCESS_STATUS;
			var outBound = flow.OUT_BOUND_STATUS;
			var deliver = flow.DELIVER_STATUS;
			var finish = flow.FINISH_STATUS;

			var info = '';
			switch(status){
				case 3:
					info = '您的订单已提交，系统将为您的订单分配处理人员，请耐心等待订单处理信息。';
					$('#STATUS').addClass('red');
					break;	
				case 4:
					info = '您的订单已在配货中。';
					$('#STATUS').addClass('red');
					break;
				case 5:
					info = '您的订单已经出库，我们将尽快为您的订单安排发货。';
					$('#STATUS').addClass('red');
					break;
				case 6:
					info = '您的订单商品已发出，请保持您的联系电话通畅，方便物流人员第一时间与您联系。';
					$('#STATUS').addClass('red');
					break;
				case 7:
					info = '订单已经完成，感谢您在金麟贝贝母婴商城购物。';
					if(order.IS_COMMENT == 0){
						info = '订单已经完成，感谢您在金麟贝贝母婴商城购物，欢迎您对本次交易及所购商品进行评价。';
						$('#msg_btn').show();
					}
					$('#STATUS').addClass('green');
					break;
				case 8:
					info = '交易取消原因：' + order.PROCESS_RESULT;
//					$('#order_log_list').hide();
					$('#process').hide();
					break;
			}
			$('#order_status_info').html(info);
			
			var div = '';
			div += '<div class="node '+getPointStaus(status, 3)+'"><ul><li class="tx1">&nbsp;</li><li class="tx2">提交订单</li><li class="tx3">'+$Util.toChar(newOrder, 'yyyy-mm-dd')+'<br />'+$Util.toChar(newOrder, 'hh24:mi:ss')+'</li></ul></div>';
			div += '<div class="proce '+getLineStaus(status, 3)+'"><ul><li class="tx1">&nbsp;</li></ul></div>';
			div += '<div class="node '+getPointStaus(status, 4)+'"><ul><li class="tx1">&nbsp;</li><li class="tx2">配货中</li><li class="tx3">'+$Util.toChar(proccess, 'yyyy-mm-dd')+'<br />'+$Util.toChar(proccess, 'hh24:mi:ss')+'</li></ul></div>';
			div += '<div class="proce '+getLineStaus(status, 4)+'"><ul><li class="tx1">&nbsp;</li></ul></div>';
			div += '<div class="node '+getPointStaus(status, 5)+'"><ul><li class="tx1">&nbsp;</li><li class="tx2">商品出库</li><li class="tx3">'+$Util.toChar(outBound, 'yyyy-mm-dd')+'<br />'+$Util.toChar(outBound, 'hh24:mi:ss')+'</li></ul></div>';
			div += '<div class="proce '+getLineStaus(status, 5)+'"><ul><li class="tx1">&nbsp;</li></ul></div>';
			div += '<div class="node '+getPointStaus(status, 6)+'"><ul><li class="tx1">&nbsp;</li><li class="tx2">等待收货</li><li class="tx3">'+$Util.toChar(deliver, 'yyyy-mm-dd')+'<br />'+$Util.toChar(deliver, 'hh24:mi:ss')+'</li></ul></div>';
			div += '<div class="proce '+getLineStaus(status, 6)+'"><ul><li class="tx1">&nbsp;</li></ul></div>';
			div += '<div class="node '+getPointStaus(status, 7)+'"><ul><li class="tx1">&nbsp;</li><li class="tx2">完成</li><li class="tx3">'+$Util.toChar(finish, 'yyyy-mm-dd')+'<br />'+$Util.toChar(finish, 'hh24:mi:ss')+'</li></ul></div>';
			$('#process').html(div);
			
			$('#ORDER_ID').html(order.ORDER_ID);
			$('#STATUS').html($Base.getOrderStatus(status));
			$('#CONSIGNEE_NAME').html(order.CONSIGNEE);
			$('#ADDRESS').html(order.FINAL_ADDRESS);
			$('#MOBILE').html(order.MOBILE);
			$('#TELEPHONE').html(order.TELEPHONE);
			$('#ZIP_CODE').html(order.ZIP_CODE);
			$('#PAY_METHOD').html($Base.getPayMethod(order.PAY_METHOD));
			$('#DELIVER_METHOD').html($Base.getDeliverMethod(order.DELIVER_METHOD));
			$('#DELIVER_TIME').html($Base.getDeliverTime(order.DELIVER_TIME));
			$('#MESSAGE').html(order.MESSAGE == '' ? '无' : order.MESSAGE);
			$('#AMOUNT').html("￥" + (order.PAYMENT).toFixed(2));
			
			var logList = '';
			$.each(log, function(i, o){
				logList += '<tr>';          
				logList += 	'<td>' + $Util.toChar(o.CHANGE_DATE, 'yyyy-mm-dd hh24:mi:ss') + '</td>';
				logList += 	'<td>' + o.CONTENT + '</td>';
				logList += 	'<td>' + o.OPERATOR_NAME+ '</td>';
				logList += '</tr>';
			});
			$('#log_list').append(logList);
			
			var productList = '';
			$.each(detail, function(i, o){
				productList += '<tr>';          
				productList += 	'<td>' + o.PRODUCT_NO + '</td>';
				productList += 	'<td><div align="left"><a href="../product/file.html?id='+o.PRODUCT_ID+'" class="blue"><img src="../upload/product/'+o.PRODUCT_NO+'.jpg" style="width:50px;height:50px;border:1px solid #E9E9E9;" align="absmiddle"/></a>' +
						'&nbsp;<a href="../product/file.html?id='+o.PRODUCT_ID+'" class="blue">' + o.PRODUCT_NAME + '</a></div></td>';
				productList += 	'<td><span class="ftx04">￥' + (o.MEMBER_PRICE).toFixed(2)+ '</span></td>';
				productList += 	'<td><span">' + o.POINT+ '</span></td>';
				productList += 	'<td>' + o.QTY+ '</td>';
				productList += 	'<td><span class="ftx04">￥' + (o.AMOUNT).toFixed(2)+ '</span></td>';
				productList += '</tr>';
			});
			$('#product_list').append(productList);
		}
	}, 'json');
}

function getPointStaus(currentStatus, status){
	var className = 'wait';
	if(currentStatus < status){
		className = 'wait';
	}
	else if(currentStatus == status){
		className = 'ready';
	}
	else if(currentStatus > status){
		className = 'ready';
	}
	return className;
}

function getLineStaus(currentStatus, status){
	var className = 'wait';
	if(currentStatus < status){
		className = 'wait';
	}
	else if(currentStatus == status){
		className = 'doing';
	}
	else if(currentStatus > status){
		className = 'ready';
	}
	return className;
}
